package com.ruoyi.history.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.history.domain.FlywaySchemaHistory;
import com.ruoyi.history.service.IFlywaySchemaHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据库信息管理Controller
 * 
 * @author yx
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/history/history")
public class FlywaySchemaHistoryController extends BaseController
{
    @Autowired
    private IFlywaySchemaHistoryService flywaySchemaHistoryService;

    /**
     * 查询数据库信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('history:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlywaySchemaHistory flywaySchemaHistory)
    {
        startPage();
        List<FlywaySchemaHistory> list = flywaySchemaHistoryService.selectFlywaySchemaHistoryList(flywaySchemaHistory);
        return getDataTable(list);
    }

    /**
     * 导出数据库信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('history:history:export')")
    @Log(title = "数据库信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlywaySchemaHistory flywaySchemaHistory)
    {
        List<FlywaySchemaHistory> list = flywaySchemaHistoryService.selectFlywaySchemaHistoryList(flywaySchemaHistory);
        ExcelUtil<FlywaySchemaHistory> util = new ExcelUtil<FlywaySchemaHistory>(FlywaySchemaHistory.class);
        util.exportExcel(response, list, "数据库信息管理数据");
    }

    /**
     * 获取数据库信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('history:history:query')")
    @GetMapping(value = "/{installedRank}")
    public AjaxResult getInfo(@PathVariable("installedRank") Long installedRank)
    {
        return success(flywaySchemaHistoryService.selectFlywaySchemaHistoryByInstalledRank(installedRank));
    }

    /**
     * 新增数据库信息管理
     */
    @PreAuthorize("@ss.hasPermi('history:history:add')")
    @Log(title = "数据库信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlywaySchemaHistory flywaySchemaHistory)
    {
        return toAjax(flywaySchemaHistoryService.insertFlywaySchemaHistory(flywaySchemaHistory));
    }

    /**
     * 修改数据库信息管理
     */
    @PreAuthorize("@ss.hasPermi('history:history:edit')")
    @Log(title = "数据库信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlywaySchemaHistory flywaySchemaHistory)
    {
        return toAjax(flywaySchemaHistoryService.updateFlywaySchemaHistory(flywaySchemaHistory));
    }

    /**
     * 删除数据库信息管理
     */
    @PreAuthorize("@ss.hasPermi('history:history:remove')")
    @Log(title = "数据库信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{installedRanks}")
    public AjaxResult remove(@PathVariable Long[] installedRanks)
    {
        return toAjax(flywaySchemaHistoryService.deleteFlywaySchemaHistoryByInstalledRanks(installedRanks));
    }
}
